package com.yztc.orangeentertainment.ui.main.findfragment.findadapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yztc.orangeentertainment.R;
import com.yztc.orangeentertainment.bean.findbean.HotSearchStarListBean;
import com.yztc.orangeentertainment.ui.main.channalarticle.ChannalArticleActivity;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by My on 2016/10/9.
 */
public class SearchSatrRlvAdapter extends RecyclerView.Adapter<SearchSatrRlvAdapter
        .SearchStarViewHolder> {
    private Context context;
    private List<HotSearchStarListBean> list;

    public SearchSatrRlvAdapter(Context context, List<HotSearchStarListBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public SearchStarViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        SearchStarViewHolder holder = new SearchStarViewHolder(LayoutInflater.from(context)
                .inflate(R.layout.findsearchstar_rlv, null));
        return holder;
    }

    @Override
    public void onBindViewHolder(SearchStarViewHolder holder, final int position) {
        holder.hotsearchTv.setText(list.get(position).getTitle());
        Glide.with(context).load(list.get(position).getPic()).into(holder.hotsearchIv);
        holder.needclick.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ChannalArticleActivity.class);
                intent.putExtra("id", list.get(position).getId() + "");
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class SearchStarViewHolder extends RecyclerView.ViewHolder {
        @InjectView(R.id.hotsearch_tv)
        TextView hotsearchTv;
        @InjectView(R.id.hotsearch_iv)
        ImageView hotsearchIv;
        @InjectView(R.id.needclick)
        RelativeLayout needclick;

        public SearchStarViewHolder(View itemView) {
            super(itemView);
            ButterKnife.inject(this, itemView);
        }
    }
}
